#include"Sem.hpp"
#include"RingQueue.hpp"
#include<iostream>
#include<unistd.h>
#include<pthread.h>
#include<semaphore.h>

void* producer(void* arg){
    RingQueue<int> *bq=(RingQueue<int>*)arg;
      int t=0;
    while(true){
        t++;
        bq->Enqueue(t);
        std::cout<<"Produced "<<t<<std::endl;
        sleep(1);
    }
}
void* consumer(void* arg){
    RingQueue<int> *bq=(RingQueue<int>*)arg;
    while(true){
        int t=0;
        bq->Pop(t);
        std::cout<<"Consumed "<<t<<std::endl;
        sleep(2);
    }
}
int main(){
    RingQueue<int> *rq=new RingQueue<int>();
    pthread_t prod,cons;
    pthread_create(&prod,NULL,producer,rq);
    pthread_create(&cons,NULL,consumer,rq);
    pthread_join(prod,NULL);
    pthread_join(cons,NULL);
    return 0;
}